//
//  QLNewPersonalHomeCell.m
//  神约
//
//  Created by qlwl on 16/12/29.
//  Copyright © 2016年 qlwl. All rights reserved.
//

#import "QLNewPersonalHomeCell.h"
#import "UIView+FrameKIt.h"

@implementation QLNewPersonalAboutTaCell
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    _skView1 = [[SKTagView alloc] initWithFrame:CGRectZero];
    _skView1.lineSpacing = 8;
    _skView1.interitemSpacing = 12;
    //_skView.preferredMaxLayoutWidth = iphoneWidth;
    [self.tagBgView1 addSubview:_skView1];
    _skView2 = [[SKTagView alloc] initWithFrame:CGRectZero];
    _skView2.lineSpacing = 8;
    _skView2.interitemSpacing = 12;
    //_skView.preferredMaxLayoutWidth = iphoneWidth;
    [self.tagBgView2 addSubview:_skView2];
    _skView3 = [[SKTagView alloc] initWithFrame:CGRectZero];
    _skView3.lineSpacing = 8;
    _skView3.interitemSpacing = 12;
    //_skView.preferredMaxLayoutWidth = iphoneWidth;
    [self.tagBgView3 addSubview:_skView3];
}

- (void)setDataArray1:(NSArray *)dataArray1
{
    _dataArray1 = dataArray1;
    [self refreshSk1WithItem:_dataArray1];
}
- (void)refreshSk1WithItem:(NSArray *)itemArray
{
    [_skView1 removeAllTags];
    _skView1.preferredMaxLayoutWidth = iphoneWidth - 84;
    [itemArray enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        NSString * title = obj;
        // 初始化标签
        SKTag *tag = [self getATagWithTitle:title isSelect:NO];
        // 加入到tagView
        [_skView1 addTag:tag];
    }];
    typeof(self)t_self = self;
    _skView1.didTapTagAtIndex = ^(NSUInteger idx){
        
    };
    _skView1.frame = CGRectMake(0, 0, _skView1.preferredMaxLayoutWidth, _skView1.intrinsicContentSize.height);
    
    self.f_height = self.f_height - self.layoutTagBg1Height.constant + MAX(_skView1.intrinsicContentSize.height, 20);
    self.layoutTagBg1Height.constant = MAX(_skView1.intrinsicContentSize.height, 20);
    
}

- (void)setDataArray2:(NSArray *)dataArray2
{
    _dataArray2 = dataArray2;
    [self refreshSk2WithItem:_dataArray2];
}
- (void)refreshSk2WithItem:(NSArray *)itemArray
{
    [_skView2 removeAllTags];
    _skView2.preferredMaxLayoutWidth = iphoneWidth - 84;
    [itemArray enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        NSString * title = obj;
        // 初始化标签
        SKTag *tag = [self getATagWithTitle:title isSelect:NO];
        // 加入到tagView
        [_skView2 addTag:tag];
    }];
    typeof(self)t_self = self;
    _skView2.didTapTagAtIndex = ^(NSUInteger idx){
        
    };
    _skView2.frame = CGRectMake(0, 0, _skView1.preferredMaxLayoutWidth, _skView1.intrinsicContentSize.height);
    
    self.f_height = self.f_height - self.layoutTagBg2Height.constant + MAX(_skView2.intrinsicContentSize.height, 20);
    self.layoutTagBg2Height.constant = MAX(_skView2.intrinsicContentSize.height, 20);
}
- (void)setDataArray3:(NSArray *)dataArray3
{
    _dataArray3 = dataArray3;
    [self refreshSk3WithItem:_dataArray3];
    
}
- (void)refreshSk3WithItem:(NSArray *)itemArray
{
    [_skView3 removeAllTags];
    _skView3.preferredMaxLayoutWidth = iphoneWidth - 84;
    [itemArray enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        NSString * title = obj;
        // 初始化标签
        SKTag *tag = [self getATagWithTitle:title isSelect:NO];
        // 加入到tagView
        [_skView3 addTag:tag];
    }];
    typeof(self)t_self = self;
    _skView3.didTapTagAtIndex = ^(NSUInteger idx){
        
    };
    _skView3.frame = CGRectMake(0, 0, _skView3.preferredMaxLayoutWidth, _skView3.intrinsicContentSize.height);
    
    self.f_height = self.f_height - self.layoutTagBg3Height.constant + MAX(_skView3.intrinsicContentSize.height, 20);
    self.layoutTagBg3Height.constant = MAX(_skView3.intrinsicContentSize.height, 20);
}

- (SKTag *)getATagWithTitle:(NSString *)title isSelect:(BOOL)select
{
    SKTag *tag = [[SKTag alloc] initWithText:title];
    // 标签相对于自己容器的上左下右的距离
    
    tag.padding = UIEdgeInsetsMake(3, 10, 3, 10);
    // 弧度
    tag.cornerRadius = 3.0f;
    // 字体
    tag.font = [UIFont systemFontOfSize:13];
    // 边框宽度
    tag.borderWidth = .5f;
    // 背景
    tag.bgColor = [UIColor whiteColor];
    // 边框颜色
    tag.borderColor = [UIColor colorWithRed:0.89f green:0.89f blue:0.89f alpha:1.00f];
    // 字体颜色
    if (select) {
        tag.textColor = [UIColor colorWithRed:1.00f green:0.35f blue:0.00f alpha:1.00f];
    }else{
        tag.textColor = [UIColor blackColor];
    }
    
    //tag.bgImg = [UIImage imageNamed:@"scrreenCategoryBg"] ;//[[UIImage imageNamed:@"scrreenCategoryBg"] resizableImageWithCapInsets:UIEdgeInsetsMake(10,30,10,30) resizingMode:UIImageResizingModeStretch];
    tag.highlightedBgColor = [UIColor whiteColor];
    // 是否可点击
    tag.enable = YES;
    return tag;
}

@end

@implementation QLNewPersonalImpressCell
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if ([super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellAccessoryNone;
//        self.backgroundColor = [UIColor clearColor];
//        self.contentView.backgroundColor = [UIColor clearColor];
        _titLab = [[UILabel alloc] initWithFrame:CGRectZero];
        _titLab.textColor = [UIColor blackColor];
        _titLab.font = [UIFont systemFontOfSize:14];
        _titLab.textColor = [UIColor lightGrayColor];
        [self.contentView addSubview:_titLab];
        
        _skView = [[SKTagView alloc] initWithFrame:CGRectZero];
        _skView.lineSpacing = 8;
        _skView.interitemSpacing = 12;
        //_skView.preferredMaxLayoutWidth = iphoneWidth;
        [self.contentView addSubview:_skView];
    }
    return self;
}
- (void)setItemArray:(NSArray *)itemArray
{
    _itemArray = itemArray;
    [self refreshScreenItem:_itemArray];
}
- (void)refreshScreenItem:(NSArray *)itemArray
{
    [_skView removeAllTags];
    _titLab.f_left = 8;
    _titLab.f_top = 8 + 3;
    [_titLab sizeToFit];
    _skView.preferredMaxLayoutWidth = iphoneWidth - _titLab.f_width - 8 - 8 - 8;
    [itemArray enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        NSString * title = obj;
        // 初始化标签
        SKTag *tag = [self getATagWithTitle:title isSelect:NO];
        // 加入到tagView
        [_skView addTag:tag];
    }];
    typeof(self)t_self = self;
    _skView.didTapTagAtIndex = ^(NSUInteger idx){
        
    };
    _skView.f_left = _titLab.f_right + 8;
    _skView.f_top = 8;
    _skView.f_height = _skView.intrinsicContentSize.height;
    _skView.f_width = _skView.preferredMaxLayoutWidth;
    self.f_height = _skView.f_bottom + 8;
}
- (SKTag *)getATagWithTitle:(NSString *)title isSelect:(BOOL)select
{
    SKTag *tag = [[SKTag alloc] initWithText:title];
    // 标签相对于自己容器的上左下右的距离
    
    tag.padding = UIEdgeInsetsMake(3, 10, 3, 10);
    // 弧度
    tag.cornerRadius = 3.0f;
    // 字体
    tag.font = [UIFont systemFontOfSize:13];
    // 边框宽度
    tag.borderWidth = .5f;
    // 背景
    tag.bgColor = [UIColor whiteColor];
    // 边框颜色
    tag.borderColor = [UIColor colorWithRed:0.89f green:0.89f blue:0.89f alpha:1.00f];
    // 字体颜色
    if (select) {
        tag.textColor = [UIColor colorWithRed:1.00f green:0.35f blue:0.00f alpha:1.00f];
    }else{
        tag.textColor = [UIColor blackColor];
    }
    
    //tag.bgImg = [UIImage imageNamed:@"scrreenCategoryBg"] ;//[[UIImage imageNamed:@"scrreenCategoryBg"] resizableImageWithCapInsets:UIEdgeInsetsMake(10,30,10,30) resizingMode:UIImageResizingModeStretch];
    tag.highlightedBgColor = [UIColor whiteColor];
    // 是否可点击
    tag.enable = YES;
    return tag;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
}



@end

@implementation QLNewPersonalGiftCell
#define GInteritemSpacing (16)
#define GInterNum (5)
#define GCellWidth (iphoneWidth-(GInterNum - 1)*GInteritemSpacing - 84 - 8)/GInterNum
#define GCellHeight (GCellWidth / 4*5)


- (void)setImaArray:(NSMutableArray *)imaArray
{
    _imaArray = imaArray;
    
    ((UICollectionViewFlowLayout *)self.collectionView.collectionViewLayout).minimumLineSpacing = GInteritemSpacing;
    ((UICollectionViewFlowLayout *)self.collectionView.collectionViewLayout).minimumInteritemSpacing = GInteritemSpacing;
    [self.collectionView reloadData];
    
    if (_maxItemNum == 0) {
        _maxItemNum = 12;
    }
    int itemNum = imaArray.count < _maxItemNum?(int)imaArray.count + 1:(int)imaArray.count;
    int lineNum = itemNum%GInterNum?itemNum/GInterNum :itemNum/GInterNum + 1;
    float cellHeight = lineNum * (GInterNum + GCellHeight) - GInteritemSpacing + 2*8 + 1;
    if (cellHeight < (GCellHeight + 2* 8)) {
        self.f_height = GCellHeight + 2* 8;
    }else{
        self.f_height = cellHeight;
    }
    
}

#pragma mark CollectionViewDelegate
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    if (_imaArray.count<_maxItemNum) {
        return _imaArray.count+1;
    }
    return _imaArray.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    UICollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    return cell;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return CGSizeMake(GCellWidth, GCellHeight);
}

-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    return UIEdgeInsetsMake(0,0,0,0);
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    
}
- (BOOL) shouldPerformSegueWithIdentifier:(NSString *)identifier sender:(id)sender
{
    return YES;
}


@end

@implementation QLNewPersonalLoveCell

@end

@implementation QLNewPersonalDynamicIdentifCell

@end

@implementation QLNewPersonalDynamicCell

@end

@implementation QLNewPersonalInvitedCell

- (void)setItemArray:(NSMutableArray *)itemArray
{
    _itemArray = itemArray;
    
    float cellHeight = 36 * _itemArray.count;
    if (cellHeight < 60) {
        
    }
    self.f_height = cellHeight < 60 ?60:cellHeight;
    [self.tableView reloadData];
}

#pragma mark TabDelegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _itemArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 36;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}


@end


@implementation QLNewPersonalPhotoCell
#define InteritemSpacing (8)
#define InterNum (4)
#define CellWidth (iphoneWidth-(InterNum - 1)*InteritemSpacing - 84 - 8)/InterNum
#define CellHeight (CellWidth)


- (void)setImaArray:(NSMutableArray *)imaArray
{
    _imaArray = imaArray;
    
    ((UICollectionViewFlowLayout *)self.collectionView.collectionViewLayout).minimumLineSpacing = InteritemSpacing;
    ((UICollectionViewFlowLayout *)self.collectionView.collectionViewLayout).minimumInteritemSpacing = InteritemSpacing;
    [self.collectionView reloadData];
    
    if (_maxLineNum == 0) {
        _maxLineNum = 1;
    }
    
    float cellHeight = _maxLineNum * (CellHeight + InteritemSpacing) - InteritemSpacing + 2*8 + 1;
    if (cellHeight < (CellHeight + 2 * 8)) {
        self.f_height = CellHeight + 2 * 8;
    }else{
        self.f_height = cellHeight;
    }
    
}

#pragma mark CollectionViewDelegate
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    
    return MIN(_imaArray.count, _maxLineNum * InterNum);
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    UICollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    return cell;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return CGSizeMake(CellWidth, CellHeight);
}

-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    return UIEdgeInsetsMake(0,0,0,0);
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    
}
- (BOOL) shouldPerformSegueWithIdentifier:(NSString *)identifier sender:(id)sender
{
    return YES;
}


@end

@implementation QLNewPersonalHomeCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
